package org.example.controller;

import org.example.utils.ResponseResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Rommel
 * @version 1.0
 * @date 2023/6/13-17:20
 * @description TODO
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {


    @GetMapping("/userDetails")
    @PreAuthorize("hasAuthority('ADMIN')")
    public ResponseResult userDetails(){
        UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return ResponseResult.ok(userDetails);
    }

}
